Sync: Introduce CPT and helper for Activity Log entries#48567
Conversation
…lly meant to pass information to the Activity Log
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Code Coverage SummaryCoverage changed in 6 files. Only the first 5 are listed here.
1 file is newly checked for coverage.
|
| /** | ||
| * Testing the core REST CPT endpoint creates and normalizes a custom Activity Log event. | ||
| */ | ||
| public function test_core_rest_activity_log_event_endpoint_creates_event() { |
There was a problem hiding this comment.
Noting that these are not really testing REST_Endpoints anymore, they’re testing a core REST route registered by the CPT. But for this PR, I've kept them here because this file already sets up a REST server and dispatches requests.
…ks and a stricter REST route guard
fgiannar
left a comment
There was a problem hiding this comment.
Great work overall!
Left a few comments mainly around performance concerns but also a bug on WPCOM with the route check logic
cf3ef5b to
e9c8b1c
Compare
fgiannar
left a comment
There was a problem hiding this comment.
LGTM 🚢
Tested with a self-hosted and Simple site via the Dev console and everything works as expected 👍
Thanks for the unit test coverage too 👍
Fixes ACTLOG-57
Requires 215994-ghe-Automattic/wpcom to be deployed first to prevent WPcom test failures.
Proposed changes
Adds a Jetpack Sync helper class for creating custom customer-visible Activity Log entries.
Automattic\Jetpack\Sync\Activity_Log_Eventas the API for creating custom Activity Log events.jp_act_log_eventCPT for transporting custom Activity Log event payloads through Sync.post_content.titleandcontentsourceseveritylimited toinfo,success,warning, orerror{ title, content, source, severity }into the canonical JSON payload.jetpack_published_postSync pipeline.jp_act_log_eventposts so remote/cache DB state stays consistent.jp_act_log_eventinserts so invalid severity values, empty sanitized content, and malformed payloads are not enqueued throughjetpack_published_post.Related product discussion/links
This is part of an RSM project to add custom entries to the Activity Log. See Linear link above for more.
Requires the matching WPcom Activity Log handling in 215249-ghe-Automattic/wpcom, which translates valid
jp_act_log_eventposts intocustom_event__createdentries and prevents malformed payloads from falling through as generic post publish events.Does this pull request change what data or activity we track or use?
No.
Testing instructions
To test, apply this PR on a test site using the Jetpack Beta tester plugin, for the Jetpack plugin (or apply the PR if testing locally).
yoursite.com/wp-admin/?test_activity_log=1case 'jetpack_published_post':inJetpack_Sync_Server_ReplicatorTo test the endpoint via WPcom:
wpshand run the following:You can run the following in
wpshto confirm a response, or wait for the entry to show on the AL:To confirm that unauthenticated rrequests are not allowed, run the same test but remove the
user_id. You should get aninvalid_user_permission_activity_log_event401 response.For Simple sites, testing via the Developer API console may be easier here: